{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "# 待补充路径\n",
    "path = r'D:\\coding\\melody-generator-gan\\src\\sangle_save\\rmcgenera_{}.npy'\n",
    "sentence_length = 20 # 以sentence_length个音调为一个句子"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "# 预处理中用于处理第4列数据的函数，将数值转化为以unit为单位最接近的数\n",
    "def approximate(d):\n",
    "    unit = 0.25\n",
    "    flag = True\n",
    "    if d < 0:\n",
    "        flag = False\n",
    "        d = -d\n",
    "    quotient = int(d / unit)\n",
    "    remainder = d % unit\n",
    "\n",
    "    if flag:\n",
    "        if remainder < unit / 2:\n",
    "            return unit * quotient\n",
    "        else:\n",
    "            return unit * (quotient + 1)\n",
    "    else:\n",
    "        if remainder < unit / 2:\n",
    "            return -(unit * quotient)\n",
    "        else:\n",
    "            return -(unit * (quotient + 1))\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "# 预处理数据，生成的数据3列中，第3与第5列取整，第4列以0.25为单位取整\n",
    "def pre_process(path):\n",
    "    data = np.load(path, allow_pickle=True)\n",
    "\n",
    "    data_T = data.T\n",
    "    data_T[3] = np.round(data_T[3])\n",
    "    data_T[5] = np.round(data_T[5])\n",
    "\n",
    "    for pitch in range(0, len(data_T[4])):\n",
    "        for sentence in range(0, len(data_T[4][pitch])):\n",
    "            data_T[4][pitch][sentence] = approximate(data_T[4][pitch][sentence])\n",
    "\n",
    "    data = data_T.T\n",
    "    return data"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "# MIDI numbers span：平均每个句子的 midi数字跨度和（最大音高-最小音高）\n",
    "def getMIDI_numbers_span(data):\n",
    "    MIDI_numbers_spans = []\n",
    "\n",
    "    for sentence in data:\n",
    "        maxpitch = sentence[0][3]\n",
    "        minpitch = sentence[0][3]\n",
    "        for pitch in sentence:\n",
    "            maxpitch = max(maxpitch, pitch[3])\n",
    "            minpitch = min(minpitch, pitch[3])\n",
    "\n",
    "        MIDI_numbers_span = maxpitch - minpitch\n",
    "        MIDI_numbers_spans.append(MIDI_numbers_span)\n",
    "\n",
    "    # print(MIDI_numbers_spans)\n",
    "    mean = np.mean(MIDI_numbers_spans)\n",
    "    return mean"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [],
   "source": [
    "# Number of Unique MIDI note in every song：每首歌一共生成了多少个不同的音高(一个文件500句为一首歌)\n",
    "def getNumber_of_Unique_MIDI_note_in_every_song(data):\n",
    "    y = []\n",
    "    for sentence in data:\n",
    "        for pitch in sentence:\n",
    "            y.append(pitch[3])\n",
    "\n",
    "    x = set(y)\n",
    "    Number_of_Unique_MIDI_note = len(x)\n",
    "    return Number_of_Unique_MIDI_note"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "# Number of Unique MIDI note in every sentence： 每句一共生成了多少个不同的音高\n",
    "def getNumber_of_Unique_MIDI_note_in_every_sentence(data):\n",
    "    Numbers_of_Unique_MIDI_note = []\n",
    "    for sentence in data:\n",
    "        y = []\n",
    "        for pitch in sentence:\n",
    "            y.append(pitch[3])\n",
    "\n",
    "        x = set(y)\n",
    "        Numbers_of_Unique_MIDI_note.append(len(x))\n",
    "\n",
    "    mean = np.mean(Numbers_of_Unique_MIDI_note)\n",
    "    return mean"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [],
   "source": [
    "# Number of rest in every sentence：平均每句出现休止符数量\n",
    "def getNumber_of_rest_in_every_sentence(data):\n",
    "    Numbers_of_rest_in_every_sentence = []\n",
    "    for sentence in data:\n",
    "        number_of_rest = 0\n",
    "        for pitch in sentence:\n",
    "            rest = pitch[5]\n",
    "            if rest > 0:\n",
    "                number_of_rest += 1\n",
    "\n",
    "        Numbers_of_rest_in_every_sentence.append(number_of_rest)\n",
    "\n",
    "    mean = np.mean(Numbers_of_rest_in_every_sentence)\n",
    "    return mean"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [],
   "source": [
    "# Sum length of rest value in every sentence：平均每句的平均休止符长度(按中文意思)\n",
    "def getSum_length_of_rest_value_in_every_sentence(data):\n",
    "    Sum_length_of_rest_values = []\n",
    "    for sentence in data:\n",
    "        Sum_length_of_rest_value = 0\n",
    "        for pitch in sentence:\n",
    "            rest = pitch[5]\n",
    "            Sum_length_of_rest_value += rest\n",
    "\n",
    "        temp = Sum_length_of_rest_value / sentence_length\n",
    "        Sum_length_of_rest_values.append(temp)\n",
    "\n",
    "    mean = np.mean(Sum_length_of_rest_values)\n",
    "    return mean"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [],
   "source": [
    "# sum time length of every sentence：每个句子的平均时间总长度【所有音符的音符长度与休止符长度和】\n",
    "def getSum_time_length_of_every_sentence(data):\n",
    "    Sum_time_length_of_sentences = []\n",
    "    for sentence in data:\n",
    "        Sum_time_length_of_every_sentence = 0\n",
    "        for pitch in sentence:\n",
    "            Sum_time_length_of_every_sentence += pitch[4] + pitch[5]\n",
    "\n",
    "        Sum_time_length_of_sentences.append(Sum_time_length_of_every_sentence)\n",
    "\n",
    "    mean = np.mean(Sum_time_length_of_sentences)\n",
    "    return mean"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [],
   "source": [
    "# transitions between MIDI numbers相邻音符之间的跨度\n",
    "def getTransitions_between_MIDI_numbers(data):\n",
    "    transitions_between_MIDI_numbers = []\n",
    "    for sentence in data:\n",
    "        transition_between_MIDI_numbers = 0\n",
    "        for pitch in range(0, sentence_length - 1):\n",
    "            temp = sentence[pitch+1][3] - sentence[pitch][3]\n",
    "            temp = abs(temp)\n",
    "            transition_between_MIDI_numbers += temp\n",
    "\n",
    "        transition_between_MIDI_numbers = transition_between_MIDI_numbers / (sentence_length - 1)\n",
    "        transitions_between_MIDI_numbers.append(transition_between_MIDI_numbers)\n",
    "\n",
    "    mean = np.mean(transitions_between_MIDI_numbers)\n",
    "    return mean"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [],
   "source": [
    "# 注意：此处的path为单个文件完整路径\n",
    "def process1(path):\n",
    "    data = pre_process(path)\n",
    "\n",
    "    MIDI_numbers_span = getMIDI_numbers_span(data)\n",
    "    print(\"MIDI_numbers_span: \"+ str(MIDI_numbers_span))\n",
    "\n",
    "    Number_of_Unique_MIDI_note_in_every_song = getNumber_of_Unique_MIDI_note_in_every_song(data)\n",
    "    print(\"Number_of_Unique_MIDI_note_in_every_song: \"+ str(Number_of_Unique_MIDI_note_in_every_song))\n",
    "\n",
    "    Number_of_Unique_MIDI_note_in_every_sentence = getNumber_of_Unique_MIDI_note_in_every_sentence(data)\n",
    "    print(\"Number_of_Unique_MIDI_note_in_every_sentence: \"+ str(Number_of_Unique_MIDI_note_in_every_sentence))\n",
    "\n",
    "    Number_of_rest_in_every_sentence = getNumber_of_rest_in_every_sentence(data)\n",
    "    print(\"Number_of_rest_in_every_sentence: \"+ str(Number_of_rest_in_every_sentence))\n",
    "\n",
    "    Sum_length_of_rest_value_in_every_sentence = getSum_length_of_rest_value_in_every_sentence(data)\n",
    "    print(\"Sum_length_of_rest_value_in_every_sentence: \"+ str(Sum_length_of_rest_value_in_every_sentence))\n",
    "\n",
    "    Sum_time_length_of_every_sentence = getSum_time_length_of_every_sentence(data)\n",
    "    print(\"Sum_time_length_of_every_sentence: \"+ str(Sum_time_length_of_every_sentence))\n",
    "\n",
    "    Transitions_between_MIDI_numbers = getTransitions_between_MIDI_numbers(data)\n",
    "    print(\"Transitions_between_MIDI_numbers: \"+ str(Transitions_between_MIDI_numbers))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [],
   "source": [
    "# 获取平均值，此处的路径为待补充路径\n",
    "def getMean(path):\n",
    "    MIDI_numbers_spans = []\n",
    "    Numbers_of_Unique_MIDI_note_in_every_song = []\n",
    "    Numbers_of_Unique_MIDI_note_in_every_sentence = []\n",
    "    Numbers_of_rest_in_every_sentence = []\n",
    "    Sums_length_of_rest_value_in_every_sentence = []\n",
    "    Sums_time_length_of_every_sentence = []\n",
    "    Transitions_between_MIDI_numbers = []\n",
    "\n",
    "    for i in range(0, 6):\n",
    "        path1 = path.format(i)\n",
    "        data = pre_process(path1)\n",
    "\n",
    "        MIDI_numbers_span = getMIDI_numbers_span(data)\n",
    "        Number_of_Unique_MIDI_note_in_every_song = getNumber_of_Unique_MIDI_note_in_every_song(data)\n",
    "        Number_of_Unique_MIDI_note_in_every_sentence = getNumber_of_Unique_MIDI_note_in_every_sentence(data)\n",
    "        Number_of_rest_in_every_sentence = getNumber_of_rest_in_every_sentence(data)\n",
    "        Sum_length_of_rest_value_in_every_sentence = getSum_length_of_rest_value_in_every_sentence(data)\n",
    "        Sum_time_length_of_every_sentence = getSum_time_length_of_every_sentence(data)\n",
    "        Transition_between_MIDI_numbers = getTransitions_between_MIDI_numbers(data)\n",
    "\n",
    "        MIDI_numbers_spans.append(MIDI_numbers_span)\n",
    "        Numbers_of_Unique_MIDI_note_in_every_song.append(Number_of_Unique_MIDI_note_in_every_song)\n",
    "        Numbers_of_Unique_MIDI_note_in_every_sentence.append(Number_of_Unique_MIDI_note_in_every_sentence)\n",
    "        Numbers_of_rest_in_every_sentence.append(Number_of_rest_in_every_sentence)\n",
    "        Sums_length_of_rest_value_in_every_sentence.append(Sum_length_of_rest_value_in_every_sentence)\n",
    "        Sums_time_length_of_every_sentence.append(Sum_time_length_of_every_sentence)\n",
    "        Transitions_between_MIDI_numbers.append(Transition_between_MIDI_numbers)\n",
    "\n",
    "    print(\"Mean:\")\n",
    "    print(\"MIDI_numbers_span: \"+ str(np.mean(MIDI_numbers_spans)))\n",
    "\n",
    "    print(\"Number_of_Unique_MIDI_note_in_every_song: \"+ str(np.mean(Numbers_of_Unique_MIDI_note_in_every_song)))\n",
    "\n",
    "    print(\"Number_of_Unique_MIDI_note_in_every_sentence: \"+ str(np.mean(Numbers_of_Unique_MIDI_note_in_every_sentence)))\n",
    "\n",
    "    print(\"Number_of_rest_in_every_sentence: \"+ str(np.mean(Numbers_of_rest_in_every_sentence)))\n",
    "\n",
    "    print(\"Sum_length_of_rest_value_in_every_sentence: \"+ str(np.mean(Sums_length_of_rest_value_in_every_sentence)))\n",
    "\n",
    "    print(\"Sum_time_length_of_every_sentence: \"+ str(np.mean(Sums_time_length_of_every_sentence)))\n",
    "\n",
    "    print(\"Transitions_between_MIDI_numbers: \"+ str(np.mean(Transitions_between_MIDI_numbers)))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [],
   "source": [
    "# 同时处理epoch50_gen_data_0 —— epoch50_gen_data_5，此处的path为\n",
    "# 形如\"C:\\\\Users\\\\Ling\\\\Desktop\\\\essay\\\\data1\\\\epoch50_gen_data_{}.npy\"的待补充路径\n",
    "def process6(path):\n",
    "    for i in range(0, 6):\n",
    "        path1 = path.format(i)\n",
    "        print(path1)\n",
    "        process1(path1)\n",
    "        print(\"\")\n",
    "\n",
    "    getMean(path)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "D:\\coding\\melody-generator-gan\\src\\sangle_save\\rmcgenera_0.npy\n",
      "MIDI_numbers_span: 2.32\n",
      "Number_of_Unique_MIDI_note_in_every_song: 9\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.23\n",
      "Number_of_rest_in_every_sentence: 19.77\n",
      "Sum_length_of_rest_value_in_every_sentence: 1.2349999999999999\n",
      "Sum_time_length_of_every_sentence: 47.7125\n",
      "Transitions_between_MIDI_numbers: 0.6521052631578947\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\sangle_save\\rmcgenera_1.npy\n",
      "MIDI_numbers_span: 2.26\n",
      "Number_of_Unique_MIDI_note_in_every_song: 9\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.2\n",
      "Number_of_rest_in_every_sentence: 19.82\n",
      "Sum_length_of_rest_value_in_every_sentence: 1.236\n",
      "Sum_time_length_of_every_sentence: 47.745\n",
      "Transitions_between_MIDI_numbers: 0.643157894736842\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\sangle_save\\rmcgenera_2.npy\n",
      "MIDI_numbers_span: 2.43\n",
      "Number_of_Unique_MIDI_note_in_every_song: 9\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.34\n",
      "Number_of_rest_in_every_sentence: 19.81\n",
      "Sum_length_of_rest_value_in_every_sentence: 1.245\n",
      "Sum_time_length_of_every_sentence: 47.91\n",
      "Transitions_between_MIDI_numbers: 0.6926315789473685\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\sangle_save\\rmcgenera_3.npy\n",
      "MIDI_numbers_span: 2.1\n",
      "Number_of_Unique_MIDI_note_in_every_song: 8\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.08\n",
      "Number_of_rest_in_every_sentence: 19.79\n",
      "Sum_length_of_rest_value_in_every_sentence: 1.233\n",
      "Sum_time_length_of_every_sentence: 47.7\n",
      "Transitions_between_MIDI_numbers: 0.603157894736842\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\sangle_save\\rmcgenera_4.npy\n",
      "MIDI_numbers_span: 2.23\n",
      "Number_of_Unique_MIDI_note_in_every_song: 8\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.2\n",
      "Number_of_rest_in_every_sentence: 19.85\n",
      "Sum_length_of_rest_value_in_every_sentence: 1.2385000000000002\n",
      "Sum_time_length_of_every_sentence: 47.825\n",
      "Transitions_between_MIDI_numbers: 0.6299999999999999\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\sangle_save\\rmcgenera_5.npy\n",
      "MIDI_numbers_span: 2.29\n",
      "Number_of_Unique_MIDI_note_in_every_song: 8\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.24\n",
      "Number_of_rest_in_every_sentence: 19.77\n",
      "Sum_length_of_rest_value_in_every_sentence: 1.2349999999999999\n",
      "Sum_time_length_of_every_sentence: 47.715\n",
      "Transitions_between_MIDI_numbers: 0.6547368421052632\n",
      "\n",
      "Mean:\n",
      "MIDI_numbers_span: 2.2716666666666665\n",
      "Number_of_Unique_MIDI_note_in_every_song: 8.5\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.215\n",
      "Number_of_rest_in_every_sentence: 19.801666666666666\n",
      "Sum_length_of_rest_value_in_every_sentence: 1.2370833333333333\n",
      "Sum_time_length_of_every_sentence: 47.76791666666666\n",
      "Transitions_between_MIDI_numbers: 0.6459649122807017\n"
     ]
    }
   ],
   "source": [
    "# def main():\n",
    "#     data = pre_process(\"epoch50_gen_data_5.npy\")\n",
    "#\n",
    "#\n",
    "# if __name__ == '__main__':\n",
    "#     main()\n",
    "\n",
    "# path = \"epoch50_gen_data_5.npy\"\n",
    "\n",
    "process6(path)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "D:\\coding\\melody-generator-gan\\src\\save_\\22_01_28\\22_01_28_17_50_41\\epoch500_gen_data_0.npy\n",
      "MIDI_numbers_span: 2.0933333333333333\n",
      "Number_of_Unique_MIDI_note_in_every_song: 23\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.07\n",
      "Number_of_rest_in_every_sentence: 1.2466666666666666\n",
      "Sum_length_of_rest_value_in_every_sentence: 0.10266666666666667\n",
      "Sum_time_length_of_every_sentence: 28.77166666666667\n",
      "Transitions_between_MIDI_numbers: 0.5835087719298245\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\save_\\22_01_28\\22_01_28_17_50_41\\epoch500_gen_data_1.npy\n",
      "MIDI_numbers_span: 2.2333333333333334\n",
      "Number_of_Unique_MIDI_note_in_every_song: 23\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.183333333333333\n",
      "Number_of_rest_in_every_sentence: 1.7666666666666666\n",
      "Sum_length_of_rest_value_in_every_sentence: 0.15516666666666665\n",
      "Sum_time_length_of_every_sentence: 30.5925\n",
      "Transitions_between_MIDI_numbers: 0.6143859649122807\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\save_\\22_01_28\\22_01_28_17_50_41\\epoch500_gen_data_2.npy\n",
      "MIDI_numbers_span: 2.13\n",
      "Number_of_Unique_MIDI_note_in_every_song: 23\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.1166666666666667\n",
      "Number_of_rest_in_every_sentence: 1.38\n",
      "Sum_length_of_rest_value_in_every_sentence: 0.1065\n",
      "Sum_time_length_of_every_sentence: 28.825833333333332\n",
      "Transitions_between_MIDI_numbers: 0.5950877192982457\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\save_\\22_01_28\\22_01_28_17_50_41\\epoch500_gen_data_3.npy\n",
      "MIDI_numbers_span: 2.1166666666666667\n",
      "Number_of_Unique_MIDI_note_in_every_song: 22\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.1166666666666667\n",
      "Number_of_rest_in_every_sentence: 1.4\n",
      "Sum_length_of_rest_value_in_every_sentence: 0.12066666666666667\n",
      "Sum_time_length_of_every_sentence: 29.38083333333333\n",
      "Transitions_between_MIDI_numbers: 0.5871929824561403\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\save_\\22_01_28\\22_01_28_17_50_41\\epoch500_gen_data_4.npy\n",
      "MIDI_numbers_span: 2.2133333333333334\n",
      "Number_of_Unique_MIDI_note_in_every_song: 24\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.1633333333333336\n",
      "Number_of_rest_in_every_sentence: 1.6333333333333333\n",
      "Sum_length_of_rest_value_in_every_sentence: 0.13683333333333333\n",
      "Sum_time_length_of_every_sentence: 29.841666666666665\n",
      "Transitions_between_MIDI_numbers: 0.6066666666666667\n",
      "\n",
      "D:\\coding\\melody-generator-gan\\src\\save_\\22_01_28\\22_01_28_17_50_41\\epoch500_gen_data_5.npy\n",
      "MIDI_numbers_span: 2.013333333333333\n",
      "Number_of_Unique_MIDI_note_in_every_song: 22\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 2.98\n",
      "Number_of_rest_in_every_sentence: 1.2\n",
      "Sum_length_of_rest_value_in_every_sentence: 0.0955\n",
      "Sum_time_length_of_every_sentence: 28.5\n",
      "Transitions_between_MIDI_numbers: 0.5728070175438598\n",
      "\n",
      "Mean:\n",
      "MIDI_numbers_span: 2.1333333333333333\n",
      "Number_of_Unique_MIDI_note_in_every_song: 22.833333333333332\n",
      "Number_of_Unique_MIDI_note_in_every_sentence: 3.105\n",
      "Number_of_rest_in_every_sentence: 1.4377777777777776\n",
      "Sum_length_of_rest_value_in_every_sentence: 0.11955555555555557\n",
      "Sum_time_length_of_every_sentence: 29.318749999999998\n",
      "Transitions_between_MIDI_numbers: 0.5932748538011697\n",
      "0.08247222222222221\n"
     ]
    }
   ],
   "source": [
    "path = r'D:\\coding\\melody-generator-gan\\src\\save_\\22_01_28\\22_01_28_17_50_41\\epoch500_gen_data_{}.npy'\n",
    "da_sample=np.load(path.format(1),allow_pickle=True)\n",
    "process6(path)\n",
    "\n",
    "url_list=[[path.format(i),0] for i in range(6)]\n",
    "def is_same(note1,note2)->bool:\n",
    "    if abs(note1-note2)<=1:\n",
    "        return True\n",
    "    else:\n",
    "        return False\n",
    "\n",
    "def cal_pitch(data):\n",
    "    total_pitch=0\n",
    "    same_pitch=0\n",
    "    for j in range(data.shape[0]):\n",
    "        for i in range(data.shape[1]):\n",
    "            # print(data[j][i])\n",
    "            total_pitch+=1\n",
    "            if is_same(data[j][i][0],data[j][i][3]):\n",
    "                same_pitch+=1\n",
    "    return same_pitch/total_pitch\n",
    "main_sum=0\n",
    "for item in url_list:\n",
    "    data=np.load(item[0],allow_pickle=True)\n",
    "    item[1]=cal_pitch(data)\n",
    "    main_sum+=item[1]\n",
    "\n",
    "print(main_sum/len(url_list))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.00012222222222222221\n"
     ]
    }
   ],
   "source": [
    "url_list=[[path.format(i),0] for i in range(6)]\n",
    "def is_same(note1,note2)->bool:\n",
    "    if abs(note1-note2)<=3:\n",
    "        return True\n",
    "    else:\n",
    "        return False\n",
    "\n",
    "def cal_pitch(data):\n",
    "    total_pitch=0\n",
    "    same_pitch=0\n",
    "    for j in range(data.shape[0]):\n",
    "        for i in range(data.shape[1]):\n",
    "            # print(data[j][i])\n",
    "            total_pitch+=1\n",
    "            if is_same(data[j][i][0],data[j][i][3]):\n",
    "                same_pitch+=1\n",
    "    return same_pitch/total_pitch\n",
    "main_sum=0\n",
    "for item in url_list:\n",
    "    data=np.load(item[0],allow_pickle=True)\n",
    "    item[1]=cal_pitch(data)\n",
    "    main_sum+=item[1]\n",
    "\n",
    "print(main_sum/len(url_list))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [],
   "source": [
    "da=np.load(r'D:\\coding\\melody-generator-gan\\src\\save_\\22_01_28\\22_01_28_17_50_41\\epoch500_gen_data_5.npy',allow_pickle=True)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [],
   "source": [
    "def pre_process(path):\n",
    "    data = np.load(path, allow_pickle=True)\n",
    "\n",
    "    data_T = data.T\n",
    "    data_T[3] = np.round(data_T[3])\n",
    "\n",
    "    data_T[5] = np.round(data_T[5])\n",
    "    for pitch in range(0, len(data_T[5])):\n",
    "        for sentence in range(0, len(data_T[5][pitch])):\n",
    "            if data_T[5][pitch][sentence] < 0:\n",
    "                data_T[5][pitch][sentence] = 0\n",
    "\n",
    "    for pitch in range(0, len(data_T[4])):\n",
    "        for sentence in range(0, len(data_T[4][pitch])):\n",
    "            temp = approximate(data_T[4][pitch][sentence])\n",
    "            if temp <= 0.25:\n",
    "                temp = 0.25\n",
    "            data_T[4][pitch][sentence] = temp\n",
    "\n",
    "    data = data_T.T\n",
    "    return data\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [],
   "source": [
    "da=pre_process(r'C:\\Users\\masaikk\\Downloads\\epoch880_gen_data_5.npy')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}